import React, { Component } from 'react'
import { NavBar, InputItem, TextareaItem, Button} from 'antd-mobile'
import AvatarSelector from '../../component/avatar-selector/avatar-selector'
import { Redirect } from 'react-router-dom'
import { connect } from 'react-redux'
import { update } from '../../redux/user.redux'
@connect(
  state=>state.user,
  {update}
)
class BossInfo extends Component{
  constructor(props){
    super(props)
    this.state={
      title:'',
      company:'',
      money:'',
      desc:'',
      avatar:'',
    }
  }
  onChange(k,v){
    this.setState({
      [k]:v
    })
  }
  render(){
    const path = this.props.location.pathname
    const redirect=  this.props.redirectTo
    return (
      <div>
        {redirect&&redirect!==path? <Redirect to={redirect}></Redirect>:null}
        <NavBar mode="dark">Boss完善信息</NavBar>
        <AvatarSelector selectAvatar={(imgname)=>{
            this.setState({
              avatar:imgname
            })
          }} />
        <InputItem onChange={(v)=>{this.onChange('title',v)}}>
          招聘职位
        </InputItem>
        <InputItem onChange={(v)=>{this.onChange('company',v)}}>
          公司名称
        </InputItem>
        <InputItem onChange={(v)=>{this.onChange('money',v)}}>
          职位薪资
        </InputItem>
        <TextareaItem rows={3} autoHeight title='职位简介' onChange={(v)=>{this.onChange('desc',v)}}></TextareaItem>
        <Button type='primary' onClick={()=>{this.props.update(this.state)}}>保存</Button>
      </div>
    )
  }
}

export default BossInfo